

void choiseMultiple(uint8_t x, uint8_t y){
  GLCD.DrawRect( x, y + 1, fontWidth, fontWidth, BLACK);
}
void choiseSingle(uint8_t x, uint8_t y){
  GLCD.DrawCircle(x + 3, y + 3, fontWidth - 2,BLACK);
}
void drawRow1(){
  GLCD.DrawLine( 0, heightMenu, widthColumn1, heightMenu, BLACK); 
}
void drawRow2(){
  GLCD.DrawLine( 0, height - heightMenu, width, height - heightMenu, BLACK);
}
void drawColumn1(){
  GLCD.DrawLine(widthColumn1, 0, widthColumn1, height - heightMenu, BLACK);
}
void drawColumn(uint8_t i){
  uint8_t widthCol = i*widthColumn2;
  GLCD.DrawLine(widthColumn1 + widthCol, 0, widthColumn1 + widthCol, height - heightMenu, BLACK);
}
void drawRight(){  
  GLCD.DrawLine( 2*width/3, 0, 2*width/3, height, BLACK);
}
void drawBorder(){
  GLCD.DrawRect(0, 0, width, height);
}
void drawFrame(){
  drawRow1();
  drawRow2();
  drawColumn1();
  drawColumn(1);
  drawBorder();  
}
void textShow(String content, uint8_t x, uint8_t y)
{
  GLCD.GotoXY(x +  distance, y + distance);
  uint8_t len = content.length();
  GLCD.print(content); 
}
void textShowCenter(String content, uint8_t x, uint8_t y, uint8_t width)
{
  uint8_t len = content.length();
  uint8_t X = x + width/2 - (len/2)*(fontWidth + 1);  
  GLCD.GotoXY(X, y);  
  GLCD.print(content);
}
void textScroll(String content, uint8_t x, uint8_t y, uint8_t width){  
  uint8_t numCols = width/(fontWidth + 1);
  uint8_t len = content.length();
  if(len < numCols)  
 { 
   GLCD.GotoXY(x, y); 
   GLCD.print(content);    
 }
  else {
    uint8_t pos = 0, line = 1, Y = y, count = 0;
    while(pos < len)
    {
      if(pos >= numCols*line) 
      {
        count = 0;
        Y = y + (fontHeight + 1)*line++ + 2*distance;
      }      
      GLCD.GotoXY(x + count*(fontWidth + 1) + 2*distance, Y); 
      count++;
      GLCD.print(content[pos++]);
    }
  }
}
void infor(String content, uint8_t number, uint8_t row)
{  
  row--;
  uint8_t x = distance, y = heightMenu + distance + row*(fontHeight + 3);
  textShow(content, x, y);
  if(number == 0 && row != 0) return;
  uint8_t len = content.length();
  GLCD.SetDot(x + len*(fontWidth + 1) + 1, y + fontHeight, BLACK);
  if(row != 0)
    textShow((String)number, x + len*(fontWidth + 1) + 2, y );
  else textShow("MS", x + len*(fontWidth + 1) + 2, y );
}
void cell(uint8_t number, String answer, bool multiple, uint8_t row, uint8_t col){
  row--;
  col--; 
  uint8_t x = widthColumn1 + 1 + col*widthColumn2, y = distance + row * (fontHeight + 1);
  String content = (String)number;
  if(number < 10) content = "00" + content;
  else if(number < 100) content = "0" + content;
  uint8_t X = x + content.length()*(fontWidth + 1) + 1;
  textShow(content, x, y);
  GLCD.SetDot(X, y + fontHeight, BLACK);
  textShow(answer, X + 1, y);
  content += answer;
  X = x + widthColumn2 - fontWidth - 2*distance;
  GLCD.SelectFont(FontNew);
  if(multiple) textShow("#", X, y + 1); 
  else textShow("*", X, y + 1);
  GLCD.SelectFont(System5x7);
}
void drawCell(int numElement){
  //GLCD.clearScreen();
  for(int i = 1; i <= numElement/3; i++)
    for(int j = 1; j <= 2; j++)
    {
      /*if((i - rowStart + 1) % 9 == 0) {
        rowStart = (rowStart + 1) % 8 + 1;
        textShow("^", width - 2*distance - fontWidth, height - heightMenu - fontHeight - distance);
        textShow("!", width - 4*distance - 2*fontWidth, height - heightMenu - fontHeight - distance);
        return;
      }*/
      if(i > 6) return;
      cell((i - 1)*2 + j, "AB", true,  i, j);
    }
}
void timeShow(){
  textShow((String)timeMinute + "'", distance, distance);
  uint8_t timeCurrent = 60 - (millis()/1000)%60;
  if(timeSecond == 1 && timeCurrent == 60) {
    timeMinute--;
    textShow("    ", distance, distance);
  }
  timeSecond = timeCurrent;
  String time;
  if(timeSecond < 10) time = "0" + (String)timeSecond;
  else time = (String)timeSecond; 
  GLCD.SelectFont(FontNew); 
  textShow(time, (fontWidth + 1)*4 - distance, distance + 2);  
}
void login(){
  uint8_t formHeight = 60, formWidth = 110, inputHeight = heightMenu, inputWidth = formWidth - 10;
  uint8_t distanceLeft = 5, distanceButtom = 3;  
  uint8_t x = (width - formWidth)/2, y = (height - formHeight)/2;
  GLCD.DrawRect(x, y, formWidth, formHeight);
  x += distanceLeft;
  y += distanceButtom;
  textShow("Ten dang nhap: ", x, y);
  GLCD.DrawRect(x, y + 10, inputWidth, inputHeight);
  textShow("Mat khau: ", x , y + 25);
  GLCD.DrawRect(x, y + 35, inputWidth, inputHeight);
}
void mouse(uint8_t x, uint8_t y){
  GLCD.GotoXY(x, y);  
  if((millis()/1000) % 2) GLCD.print("|");
  else GLCD.print(" ");
}
void drawTable(){
  timeShow();
  GLCD.SelectFont(SystemFont5x7); 
  textShow("F1 ",  distance, height - fontHeight - 2*distance);
  //if((millis()/1000) % 5 == 0 )drawCell(40);
  infor("STT", 0, 1);
  infor("-----", 0, 2);
  infor("MD", 202, 3);
  drawCell(40);
  drawFrame();
  mouse(50, height - 8);
  textShow("F1",  distance, height - fontHeight - 2*distance);
}



